﻿
Partial Class WebForm_ChangePassword
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            EmployeeID = clsAuth.GetUserID().ToString()
        End If
    End Sub
    Protected Sub btnConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
        If CheckPassword() = False Then
            EditPassword()
            MyObj.ShowMessage("Password change successful!")
        End If

    End Sub


    Private Function CheckPassword()

        Dim datPw As New clsData
        Dim sqlPw As New MyStringBuilder
        Dim dtPw As System.Data.DataTable

        sqlPw.AppendFormat("Select Password from Employee where EmployeeID ='{0}' ", EmployeeID.Replace("'", "''"))
        dtPw = datPw.GetData(sqlPw)
        If dtPw.Rows(0)("Password").ToString() <> clsAuth.EncryptPassword(txtoldPassword.Text) Then
            MyObj.ShowMessage("Your old password is wrong, please re-enter!")
            txtoldPassword.Text = ""
            txtoldPassword.Focus()
        Else
            Return False
        End If
        Return True
    End Function

    Private Sub EditPassword()

        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("Update Employee ")
        sql.AppendFormat("Set ")
        sql.AppendFormat("Password='{0}' ", clsAuth.EncryptPassword(txtnewPassword.Text))
        sql.AppendFormat("where EmployeeID='{0}' ", EmployeeID.Replace("'", "''"))

        dat.AccData(sql)
    End Sub
    Public Property EmployeeID() As String
        Get
            Return Me.lblShowEmployeeID.Text
        End Get
        Set(ByVal value As String)
            Me.lblShowEmployeeID.Text = value
        End Set
    End Property

End Class
